package com.guli.auth.controller;

import com.alibaba.fastjson.JSON;
import com.guli.auth.feign.MemberFeign;
import com.guli.auth.service.OAuth2Service;
import com.guli.auth.utils.HttpUtils;
import com.guli.auth.vo.SocialUser;
import com.guli.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/*
 * 处理社交登录请求
 * */
@Controller
@Slf4j
public class OAuth2Controller {

    @Autowired
    private OAuth2Service oAuth2Service;

    /*
     * 第一次使用session： 命令浏览器保存卡号，JSESSIONID这个Cookie
     * 以后浏览器访问哪个网站都会带上这个网站的Cookie
     * 子域之间：gulimall.com auth.gulimall.com order.gulimall.com
     * 发卡的时候，即使是子域发的卡，父域也能够使用
     * */
    @GetMapping("/oauth2.0/weibo/success")
    public String weiboLogin(@RequestParam("code") String code, HttpSession session) {
        String result = oAuth2Service.weiboLogin(code, session);
        return result;
    }
}
